<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="js/1.4.8/angular.js"></script>
</head>
<body>
<div ng-controller="myCtrl">
   <div>当前状态1：{{tip_a}}</div>
   <div>当前URL：{{current}}</div>
    <hr>
    <div>当前状态2：{{tip_b}}</div>
    <div>上页URL：{{previous}}</div>
</div>
<script type="text/javascript">
    var app = angular.module("app", [])
            .controller("myCtrl",["$rootScope","$window","$scope","$location",function ($rootScope,$window,$scope,$location) {
                // $rootScope.$on：绑定$locationChangeStart事件
                $rootScope.$on('$locationChangeStart',function (evt,current,previous) {
                    $scope.tip_a = "Url地址即将改变！";
                    var yn = $window.confirm("确定要离开吗？");
                    if(yn){
                        $location.path("/change");
                        return;
                    }
                    evt.preventDefault();
                    $scope.tip_b = "取消了Url地址的改变！";
                    $scope.current = current;
                    $scope.previous = previous;
                });

                $rootScope.$on('$locationChangeSuccess',function (evt,current,previous) {
                    $scope.tip_b = "Url地址改变完成！";
                    $scope.current = current;
                    $scope.previous = previous;
                });
            }]);
</script>
</body>
</html>